<template>
  <div>
    <el-dialog
      v-model="dialogVisible"
      :title="title"
      width="800px"
      @closed="close"
      @open="openfn"
    >
      <z-from
        ref="formz"
        colspan="12"
        label-position="left"
        label-width="100px"
        :nowdata="fromdata"
        :nowinputs="frominputs"
        size="small"
        @setpcs="setpcsfn"
      />

      <div
        v-for="(item, index) in forminput2"
        :key="index"
        class="szitem"
        @click="sztap(item)"
      >
        <span class="szindex">{{ index + 1 }}</span>
        <i
          class="iconfont"
          :class="[
            formdata[item.value] == 1
              ? 'iconicon-checkbox1'
              : 'iconicon-checkbox',
          ]"
          style="margin: 0 10px"
        ></i>
        {{ item.label }}
      </div>
      <template #footer>
        <el-button :loading="loading" type="primary" @click="updatafn">
          确定
        </el-button>
        <slot name="btnslot"></slot>
        <el-button @click="close">取消</el-button>
      </template>
    </el-dialog>
  </div>
</template>
<script>
  // import json from '@/json/camerajson'
  // import formz from '@/components/formz'
  import zFrom from '@/components/zFrom/zFrom'
  // AfterListCfg
  export default {
    name: 'Usearchedit',
    components: {
      zFrom,
    },
    emits: ['edtdatafn'],
    data() {
      return {
        dialogVisible: false,
        title: '站点配置',
        formdata: {},
        defaultdatavalue: {},
        forminputs: [],
        loading: false,
        asynccallback: '',
        frominputs: [
          { label: '所属站点', value: 'pcs', type: 'pcs', all: '1' },
        ],
        forminput2: [
          {
            label: '三天无人使用',
            value: 'b_wry',
            type: 'switch',
            labelwidth: '200px',
          },
          {
            label: '三天充电异常',
            value: 'b_bcz',
            type: 'switch',
            labelwidth: '200px',
          },
          {
            label: '离线三小时',
            value: 'b_lx',
            type: 'switch',
            labelwidth: '200px',
          },
          {
            label: '继电器异常',
            value: 'b_jdq',
            type: 'switch',
            labelwidth: '200px',
          },
        ],
        fromdata: {},
      }
    },
    methods: {
      sztap(item) {
        this.formdata[item.value] = this.formdata[item.value] == 1 ? '0' : '1'
      },
      async setpcsfn(item) {
        if (item.id) {
          // let AfterListCfg = await this.$z.$axios.post('/AfterListCfg', {
          //   pcs: item.id,
          // })
          // AfterListCfg = AfterListCfg.data
          // let fromdata = {
          //   pcs: item.id,
          //   b_wry: '0',
          //   b_bcz: '0',
          //   b_lx: '0',
          //   b_jdq: '0',
          // }
          // if (AfterListCfg.length == 1) {
          //   fromdata = { ...fromdata, ...AfterListCfg[0] }
          // }
          // this.formdata = fromdata
          // this.$refs.formz.forcesetformdatafn(fromdata)
        }
      },
      close() {
        this.dialogVisible = false
      },
      openfn() {},
      pupdatefn(data) {
        let p = this.$z.$parent.call(this, 'Usearch')
        if (p) {
          p.getdatafn()
        }
        this.$emit('edtdatafn', data)
        if (this.savestr != 'usearch/Uedt') {
          this.close()
        }
      },
      async updatafn() {
        let data = await this.$refs['formz'].validate()

        if (data.pcs != '') {
          let pcss = data.pcs.split(',')
          let getdatas = []
          pcss.forEach((e) => {
            getdatas.push(
              this.$z.$axios.post('/AfterListCfgedt', {
                ...data,
                ...this.formdata,
                pcs: e,
              })
            )
          })
          await Promise.all(getdatas)
          // let par = this.$z.parfn(AfterListCfgedt.data)
          // if (par.value == 'succeed') {
          this.$message.success('操作完成')
          this.dialogVisible = false
          // } else {
          //   this.$message.error(par.label)
          // }
        }
        // this.asynccallback(data)
      },

      show(data, asynccallback) {
        this.asynccallback = asynccallback
        // this.formdata = {}
        this.defaultdatavalue = {}

        this.dialogVisible = true
      },
    },
  }
</script>
<style>
  .szitem {
    height: 40px;
    background: rgba(255, 255, 255, 0.1);
    margin-bottom: 10px;
    padding: 0 10px;
    display: flex;
    align-items: center;
    cursor: pointer;
  }
  .szindex {
    border: 1px solid #fff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
</style>
